package com.mf.controller;

import com.mf.entity.UserTransferRecord;
import com.mf.enums.InAndOutEnum;
import com.mf.result.Result;
import com.mf.service.IUserTransferRecordService;
import com.mf.utils.EnumUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 转账记录 前端控制器
*
* @author mf
* @since 2024-06-08
*/
@RestController
@RequestMapping("/userTransferRecord")
public class UserTransferRecordController {
    @Resource
    private IUserTransferRecordService userTransferRecordService;

    /**
     * 新增转账记录
     */
    @PostMapping("/add")
    public Result<String> add(@Valid @RequestBody UserTransferRecord userTransferRecord)
    {
        if (EnumUtils.existsInEnum(InAndOutEnum.class, userTransferRecord.getType(), "status")) {
            return Result.fail("交易类型错误");
        }
        userTransferRecordService.add(userTransferRecord);
        return Result.success();
    }
    /**
     * 根据用户id查询对应的转账记录
     */
    @GetMapping("/findByUserId")
    public Result<List<UserTransferRecord>> findByUserId(@RequestParam("userId") Integer userId)
    {
        return Result.success(userTransferRecordService.findByUserId(userId));
    }
}
